package cn.itcast.wushangxiantu.BaseAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import cn.itcast.wushangxiantu.R;
import cn.itcast.wushangxiantu.UserData.GuoJiaData;

public class FindAllGuoJiaAdapter extends BaseAdapter {
    private Context context;
    private GuoJiaData guoJiaData;
    private ViewHolder viewHolder;

    public FindAllGuoJiaAdapter(Context context) {
        this.context = context;
    }

    public GuoJiaData getGuoJiaData() {
        return guoJiaData;
    }

    public void setGuoJiaData(GuoJiaData guoJiaData) {
        this.guoJiaData = guoJiaData;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (null == guoJiaData.getGuoJiaYuLan()) {
            return 0;
        } else {
            return guoJiaData.getGuoJiaYuLan().size();
        }
    }

    @Override
    public Object getItem(int i) {
        return guoJiaData.getGuoJiaYuLan().get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = View.inflate(context, R.layout.adapter_guojia_liebiao, null);
        viewHolder=new ViewHolder(view);
        viewHolder.tvName.setText(guoJiaData.getGuoJiaYuLan().get(i).getName());
        viewHolder.tvUserName.setText(guoJiaData.getGuoJiaYuLan().get(i).getUserName());
        return view;
    }

    class ViewHolder {
        public View rootView;
        public TextView tvName;
        public TextView tvUserName;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.tvName = (TextView) rootView.findViewById(R.id.tvName);
            this.tvUserName = (TextView) rootView.findViewById(R.id.tvUserName);
        }

    }
}
